/*
 * @author java_deng
 * @date 2024/12/17 9:34
 * @description
 */
package org.kaka.controller;

import org.kaka.dto.BookDto;
import org.kaka.po.BookPo;
import org.kaka.service.impl.BookServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BookController extends BaseController{
    @Autowired
    private BookServiceImpl bookService;

    @PostMapping("/list")
    public Object list(@RequestBody @Validated BookPo bookPo){
        return success(bookService.list(bookPo));
    }

    @PostMapping("/managerList")
    public Object managerList(@RequestBody @Validated BookPo bookPo){
        return success(bookService.managerList(bookPo));
    }

    @PostMapping("/audit")
    public Object audit(@RequestBody BookPo bookPo){
        bookService.audit(bookPo);
        return success("审核成功");
    }

    @PostMapping("/saveOrUpdate")
    public Object saveOrUpdate(@RequestBody @Validated BookDto bookDto){
        if(bookDto.getId()==null||bookDto.getId()==0){
            bookService.save(bookDto);
            return success("新增成功");
        }else {
            bookService.update(bookDto);
            return success("修改成功");
        }

    }

    @GetMapping("/detail")
    public Object detail(Long id){
        return success(bookService.detail(id));
    }

    @GetMapping("/delete")
    public Object delete(Long id){
        return bookService.delete(id);
    }
}
